package com.lzx.producer.controller;

import com.lzx.producer.entity.Demo1;
import com.lzx.producer.mapper.ProducerMapper;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 程序员星星
 * @date 2022/12/26
 * @Description
 */
@RestController
@RequestMapping("/producer")
public class ProducerController {
    @Resource
    private ProducerMapper producerMapper;

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    @GetMapping("/test/{msg}/{a}")
    public Demo1 sendMessageTransaction(@PathVariable String msg, @PathVariable String a) {
        rocketMQTemplate.sendMessageInTransaction("test-demo", MessageBuilder.withPayload(msg).setHeader("msg", msg).build(), a);
//        rocketMQTemplate.convertAndSend("test-demo", "olnfad");
        return producerMapper.selectById(1);
    }
}
